package logic

import (
	"context"
	"gorm.io/gorm"
	"zy/models/mysql"

	"zy/zyrpc/internal/svc"
	"zy/zyrpc/zyrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginUpdatesLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginUpdatesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginUpdatesLogic {
	return &LoginUpdatesLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginUpdatesLogic) LoginUpdates(in *zyrpc.LoginUpdatesRequest) (*zyrpc.LoginUpdatesResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.User{
		Model:     gorm.Model{ID: uint(in.UserId)},
		HeadImage: in.HeadImage,
		RealName:  in.RealName,
	}
	mysql.DB.Debug().Updates(&user)
	return &zyrpc.LoginUpdatesResponse{
		UserId: int64(user.ID),
	}, nil
}
